package com.sunny.t1;

import java.util.Stack;

//实现栈中元素逆置
public class Main {

    public static void main(String[] args) {

        Main main = new Main();

        Stack<Integer> stack = new Stack<>();
        stack.push(1);
        stack.push(2);
        stack.push(3);

        stack.forEach(System.out::println);

        main.dfs(stack);

        stack.forEach(System.out::println);

    }

    public void dfs(Stack<Integer> stack){

        if(stack.size() == 1){
            return;
        }

        int tmp = stack.pop();

        dfs(stack);

        put(stack, tmp);
    }

    //将val压入栈底
    public void put(Stack<Integer> stack, int val){

        if(stack.size() == 0){
            stack.push(val);
            return;
        }

        int tmp = stack.pop();

        put(stack, val);

        stack.push(tmp);

    }

}
